package huawei;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/***
 * 幼儿园篮球游戏
 */
public class Q106 {

//    static String teacherStr = "4,5,6,7,0,1,2";
//    static String needOrderStr = "6,4,0,1,2,5,7";

//    static String teacherStr = "4,5,6,7,0,1,2";
//    static String needOrderStr = "6,0,5,1,2,4,7";

    static String teacherStr = "1,2,3,4";
    static String needOrderStr = "1,2,3,5";

    public static void main(String[] args) {
        List<Integer> teacherInput = Arrays.stream(teacherStr.split(",")).map(String::trim).map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> needOrder = Arrays.stream(needOrderStr.split(",")).map(String::trim).map(Integer::parseInt).collect(Collectors.toList());

        LinkedList<Integer> buket = new LinkedList<>(); // 桶

        int i = 0; // 老师放球
        int ni = 0;  // 顺序的i
        StringBuilder sb = new StringBuilder();


        while (ni < needOrder.size()) {
            if (buket.contains(needOrder.get(ni))) {
                // 如果桶里面包含了需要出列的球
                if (buket.size() == 1 || Objects.equals(buket.getFirst(), needOrder.get(ni))) {
                    // 如果只有一个球或者第一个球和目标球相等
                    buket.removeFirst();
                    sb.append('L');
                    ni += 1;
                } else if (Objects.equals(buket.getLast(), needOrder.get(ni))) {
                    buket.removeLast();
                    sb.append('R');
                    ni += 1;
                } else {
                    // 如果桶里面包含了目标球，但是不在两端，不可能成功
                    System.out.println("NO");
                    return;
                }
            } else {
                // 如果桶里没有目标球，那球一定还没有放进去
                if (i >= teacherInput.size()) {
                    System.out.println("NO");
                    return;
                }
                buket.addLast(teacherInput.get(i ++));
            }
        }

        System.out.println(sb);
    }
}
